import UIManager from "./UIManager";
import MoudleName from "../MoudleName";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ToastView extends cc.Component {

    public static showToastView(text: string, duration: number = 1): void {
        UIManager.createNode('core', "ToastView", cc.find('Canvas')).then((node)=>{
            node.opacity = 0;
            cc.find('bg/lab', node).getComponent(cc.Label).string = text || '';
    
            node.stopAllActions();
            cc.tween(node).to(.25, { opacity: 250, position: cc.v3(node.x, node.y + 100) }).delay(duration).to(.25, { opacity: 0, position: cc.v2(node.x, node.y + 200) }).call(() => {
                UIManager.deleteNode("ToastView");
            }).start();
        });
    }

    // update (dt) {}
}
